package face.controller;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.apache.commons.codec.binary.Base64;

import com.alibaba.fastjson.JSON;

import face.util.ImgUtils;
@Controller
@RequestMapping("/img/")
public class ImgController {
	
	@ResponseBody
	@RequestMapping("load")
	public JSON load(String img){
		if(img==null){System.out.println("没有获取图片");}
		 try {
			 byte[] b= Base64.decodeBase64(img.getBytes());
			for(int i=0;i<b.length;i++){
				if(b[i]<0){
					b[i]+=256;
				}
			}
		String imgPath="F:/image/0.png";
		System.err.println("传你妈个棒棒糖!");
		OutputStream out=new FileOutputStream(imgPath);
		out.write(b);
		out.flush();
		out.close();
		File file=new File(imgPath);
		JSON json=ImgUtils.check(file);
		
		 return json;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
		
	}
}
